package dk.druidPro.pageModel;

/**
 * EasyUI 分页帮助类
 * 
 * 
 */

import java.util.List;

public class PageUtil {
	private int pageNum;//第几页
	private int totalCount;//共多少条记录
	private int pageSize;//每页多少条
	private int pageTotal;// 多少页
	private List  list;//分页查询后的结果
	private int startRowNum;//每页起始数据号
	private int endRowNum;//每页结束数据号
	public PageUtil(){}	
	public PageUtil(int pageNum,int pageSize) {
		this.pageTotal = (int)(Math.ceil(this.totalCount*1.0/pageSize));
		this.pageNum = pageNum;
		//如果传进来是个负值
		this.pageNum = Math.max(pageNum, 1);
		//如果传进来的值大于最大页数
		this.pageNum = Math.min(pageNum,pageTotal);
		this.pageSize = pageSize<1?20:pageSize;
		//每页起始和结束的数
		this.startRowNum = (pageNum-1)*pageSize+1;
		this.endRowNum = startRowNum+pageSize-1;
		//导航内的属性处理
		//当pageNum是第一页的时候  previous仍然为1
	}
	public int getPageNum() {
		return pageNum<1?1:(pageNum>pageTotal?pageTotal:pageNum);
	}
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getPageTotal() {
		return pageTotal;
	}
	public void setPageTotal(int pageTotal) {
		this.pageTotal = pageTotal;
	}
	public int getPageSize() {
		return pageSize<1?20:pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize<1?20:pageSize;
	}
	public List getList() {
		return list;
	}
	public void setList(List list) {
		this.list = list;
	}
	public int getStartRowNum() {
		return startRowNum;
	}
	public void setStartRowNum(int startRowNum) {
		this.startRowNum = startRowNum;
	}
	public int getEndRowNum() {
		return endRowNum;
	}
	public void setEndRowNum(int endRowNum) {
		this.endRowNum = endRowNum;
	}
}

